package com.example.scoredemo.fragment

import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import com.example.scoredemo.R
import com.example.scoredemo.widgets.MyChronometer

class DetailFragment : Fragment() {

    companion object {
        fun newInstance() = DetailFragment()
    }
    init {

    }
    private lateinit var viewModel: DetailViewModel

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.detail_fragment, container, false)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProvider(this).get(DetailViewModel::class.java)
        view?.findViewById<Button>(R.id.button10)?.setOnClickListener {
            navito()
        }
        val content = arguments?.getString("shatangju")

        Toast.makeText(activity, content, Toast.LENGTH_SHORT).show()


        lifecycle.addObserver(view?.findViewById<MyChronometer>(R.id.chronometer)!!)


    }


    fun navito() {
        var navHostController =
            activity?.supportFragmentManager?.findFragmentById(R.id.ragmentContainerView) as NavHostFragment
        navHostController.navController.navigate(R.id.action_detailFragment_to_homeFragment)
    }
}